package com.stylefeng.guns.modular.customer.warpper;

import com.stylefeng.guns.core.base.warpper.BaseControllerWarpper;
import com.stylefeng.guns.core.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.support.DateTimeKit;
import org.apache.commons.collections.MapUtils;

import java.util.Date;
import java.util.Map;

public class VisitWrapper extends BaseControllerWarpper {

    public VisitWrapper(Object obj) {
        super(obj);
    }

    @Override
    protected void warpTheMap(Map<String, Object> map) {
        map.put("visitorName", map.get("creatorName"));
        map.put("visitDate", DateTimeKit.formatDate((Date) map.get("visitDate")));
        if (map.get("feedback").equals("1")) {
            map.put("feedbackV", "是");
        }else{
            map.put("feedbackV", "否");
        }
        Integer customerCompanyId = MapUtils.getInteger(map,"customerCompanyId");
        map.put("customerCompanyName", ConstantFactory.me().getCustomerCompanyName(customerCompanyId));
        Integer editable = 0;
        if (ShiroKit.isAdmin() || ShiroKit.getUser().getId().equals(MapUtils.getInteger(map, "creatorId"))) {
            editable = 1;
        }
        map.put("editable", editable);
    }

}
